var defaultManualSpeed = 500;
var defaultAutoSpeed = 15000;
var defaultAutoSpeedEdge = 7500; // �����ٶ�������� - һ���defaultAutoSpeed

function goToPoint1(speed, gearbox, way){
	if(!speed) speed = defaultManualSpeed;
	if(gearbox != 'auto') showIntroPart('b1');
	if(way == 'throughEdge'){
		if(gearbox == 'auto'){
			
			$('#timeline .inside').animate({backgroundPosition: '-7px -42px'},defaultAutoSpeedEdge,function(){
				$('#introNav .nav li').removeClass('active').filter('.p1').addClass('active');
				$('#timeline .inside').css({backgroundPosition: '-990px -42px'});
				$('#timeline .inside').animate({backgroundPosition: '-913px -42px'},defaultAutoSpeedEdge,function(){
					$('#introNav .nav li').removeClass('active').filter('.p1').addClass('active');
					if (gearbox == 'auto') showIntroPart('b1');
					setTimeout(function(){
						introStop();
					},defaultManualSpeed);
				});
			});
			
		}else{

			$('#timeline .inside').animate({backgroundPosition: '-7px -42px'},250,function(){
				$('#introNav .nav li').removeClass('active').filter('.p1').addClass('active');
				$('#timeline .inside').css({ backgroundPosition: '-990px -42px' });
				$('#timeline .inside').animate({backgroundPosition: '-913px -42px'},250,function(){
					$('#introNav .nav li').removeClass('active').filter('.p1').addClass('active');
					if(gearbox == 'auto') showIntroPart('b1');
					setTimeout(function(){
						introStop();
					},defaultManualSpeed);
				});
			});

		}
		
	}else{
		if (!speed) speed = defaultManualSpeed;
		$('#timeline .inside').animate({backgroundPosition: '-913px -42px'},speed,function(){
			$('#introNav .nav li').removeClass('active').filter('.p1').addClass('active');
			if (gearbox == 'auto') showIntroPart('b1');
		});
	}
}
 

function goToPoint5(speed, gearbox, way){
	if(!speed) speed = defaultManualSpeed;
	if(gearbox != 'auto') showIntroPart('b5');
	if(way == 'throughEdge'){
		if(gearbox == 'auto'){
			
			$('#timeline .inside').animate({backgroundPosition: '-990px -42px'},defaultAutoSpeedEdge,function(){
				$('#introNav .nav li').removeClass('active').filter('.p5').addClass('active');
				$('#timeline .inside').css({backgroundPosition: '-7px -42px'});
				$('#timeline .inside').animate({backgroundPosition: '-97px -42px'},defaultAutoSpeedEdge,function(){
					$('#introNav .nav li').removeClass('active').filter('.p5').addClass('active');
					if(gearbox == 'auto') showIntroPart('b5');
				});
			});
			
		}else{

			$('#timeline .inside').animate({backgroundPosition: '-990px -42px'},250,function(){
				$('#introNav .nav li').removeClass('active').filter('.p5').addClass('active');
				$('#timeline .inside').css({backgroundPosition: '-7px -42px'});
				$('#timeline .inside').animate({backgroundPosition: '-97px -42px'},250,function(){
					$('#introNav .nav li').removeClass('active').filter('.p5').addClass('active');
					if(gearbox == 'auto') showIntroPart('b5');
				});
			});

		}
	}else{

		$('#timeline .inside').animate({backgroundPosition: '-97px -42px'},speed,function(){
			$('#introNav .nav li').removeClass('active').filter('.p5').addClass('active');
			if(gearbox == 'auto') showIntroPart('b5');
		});
		
	}
}

function introAutoPlay(){
	$('#introNav #playback .play').hide().parent().parent().find('.pause').show();
	if($('#introNav .nav li.active').size() > 0){
		var activePointNo = $('#introNav .nav li.active').attr('class').substr(1, 1);
	}
	if(activePointNo < 2) goToPoint2(defaultAutoSpeed, 'auto');
	if(activePointNo < 3) goToPoint3(defaultAutoSpeed, 'auto');
	if(activePointNo < 4) goToPoint4(defaultAutoSpeed, 'auto');
	if(activePointNo < 5) goToPoint5(defaultAutoSpeed, 'auto');
	goToPoint1(defaultAutoSpeed, 'auto', 'throughEdge');
}

function introStop(){
	$('#timeline .inside').stop(function(){
		$('#timeline .inside').stop();
	});
	$('#introNav #playback .pause').hide().parent().parent().find('.play').show();
}

function showIntroPart(part){
	if($.browser.msie){
		$('.introPart').hide();
		$('#intro' + part).show();
	}else{
		$('.introPart').fadeOut(defaultManualSpeed);
		$('#intro' + part).fadeIn(defaultManualSpeed);
	}
}

$(document).ready(function(){
	
	$('#introNav #playback .play a').click(function(){
		introAutoPlay();
		return false;
	});
	
	$('#introNav #playback .pause a').click(function(){
		introStop();
		return false;
	});

	$('#introNav #playback .prev a').click(function(){
		introStop();
		var activePointNo = $('#introNav .nav li.active').attr('class').substr(1, 1);
		switch (activePointNo){
			case '1': goToPoint5(defaultManualSpeed, '', 'throughEdge'); break;
			case '2': goToPoint1();
			break;
			case '3': goToPoint2();
			break;
			case '4': goToPoint3();
			break;
			case '5': goToPoint4();
			break;
		}
		return false;
	});

	$('#introNav #playback .next a').click(function(){
		introStop();
		var activePointNo = $('#introNav .nav li.active').attr('class').substr(1, 1);
		switch(activePointNo){
			case '1': goToPoint2();
			break;
			case '2': goToPoint3();
			break;
			case '3': goToPoint4();
			break;
			case '4': goToPoint5();
			break;
			case '5': goToPoint1(defaultManualSpeed, '', 'throughEdge');
			break;
		}
		return false;
	});
 
	$('#introNav .p5 a').click(function(){
		introStop();
		if(!$(this).parent().hasClass('active')) goToPoint5();
		return false;
	});

	$('#timeline .inside').css('background-position', '-913px -42px');

});

function addLoadEvent(func){
	var oldonload = window.onload;
	if(typeof window.onload != 'function'){
		window.onload = func;
	}else{
		window.onload = function(){
			if(oldonload){
				oldonload();
			}
			func();
		}
	}
}

addLoadEvent(function(){
	introAutoPlay();
});